#ifndef ROBOTLIST_H
#define ROBOTLIST_H

#include "robot.h"

#include <QAbstractListModel>

class RobotList : public QAbstractListModel
{
    Q_OBJECT

public:
    enum Roles{
        NameRole = Qt::UserRole+1,
        CheckRole
    };
    static RobotList * getInstance();
    bool updateRobot(int nID, QString strName,QString strUrdfName,
                     QString strSportIP,
                     int nSportPort,
                     QString strPerceptionIP,
                     int nPerceptionrPort,
                     QString strSlamIP,
                     int nSlamPort,
                     QString strSpeakIP,
                     int nSpeakPort,
                     QString strZeroIP,
                     int nZeroPort,
                     QString strTelemetryIP,
                     int nTelemetryPort,
                     int nLeftTool,
                     int nRightTool,
                     int nHeadType,
                    QString strUser,
                    QString strPwd,
                     QList<VideoInfo>lsVideo,
                     QString &strErr);
    bool addRobot(QString strName,QString strUrdfName,
                  QString strSportIP,
                  int nSportPort,
                  QString strPerceptionIP,
                  int nPerceptionrPort,
                  QString strSlamIP,
                  int nSlamPort,
                  QString strSpeakIP,
                  int nSpeakPort,
                  QString strZeroIP,
                  int nZeroPort,
                  QString strTelemetryIP,
                  int nTelemetryPort,
                  int nLeftTool,
                  int nRightTool,
                  int nHeadType,
                  QString strUser,
                  QString strPwd,
                  QList<VideoInfo>lsVideo,
                  QString &strErr);

    Robot* getRobotByID(int nRobotID);
    Robot * getRobotByIndex(int nIndex);
    void removeByIndex(int nIndex);
    void setCurRobot(Robot* robot);
    Robot* getCurRobot();
    int getCount();
    void setCheckByIndex(int nIndex, bool bCheck);
    QVector<Robot *> getRobotByType(int nTypeID);
    int calculateTotalWidth() const;
protected:
    explicit RobotList(QObject *parent = nullptr);
    ~RobotList();
    int getIndexByID(int nID);

signals:
    void curRobotChanged(Robot * pCurRobot, Robot * pLastRobot);

private:
    static RobotList * m_pInstance;
    QList<Robot *> m_lsRobot;
    QList<bool> m_lsChecked;
    Robot * m_pCurRobot =nullptr;

    // QAbstractItemModel interface
public:
    int rowCount(const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;
};

#endif // ROBOTLIST_H
